//
//  RootViewController.m
//  Demo1011Navigation1
//
//  Created by yang on 10-10-10.
//  Copyright 2010 www.1000phone.com. All rights reserved.
//

#import "RootViewController.h"


@implementation RootViewController
@synthesize settingBarButton;
@synthesize settingBarButtonLeft;
@synthesize segControl;

#pragma mark -
#pragma mark View lifecycle

/* viewDidLoad函数是在xib文件加载结束后调用的
   每一个UIViewController或者变种都可以有一个 xib文件
 */
- (void)viewDidLoad {
    [super viewDidLoad];

	self.title = @"我的导航器";
	/* 
	 给当前(self)的UIViewController在导航栏目中设置 
	 标题
	 */
	self.navigationItem.rightBarButtonItem = 
			self.settingBarButton;
	/* self.navigationItem.rightBarButtonItem 
		就是右边按钮的指针。
		这里把 self.settingBarButton赋值给 右边按钮
	 也就是说：如果想给当前的UIViewController设置右边按钮，就
		设置: self.navigationItem.rightBarButtonItem
	 */
	
	self.navigationItem.leftBarButtonItem =
			self.settingBarButtonLeft;
	
	self.navigationItem.titleView = self.segControl;
	/* 给中间设置非文本的信息 */
	
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}


/*
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}
*/
/*
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}
*/
/*
- (void)viewWillDisappear:(BOOL)animated {
	[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
	[super viewDidDisappear:animated];
}
*/

/*
 // Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	// Return YES for supported orientations.
	return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
 */


#pragma mark -
#pragma mark Table view data source

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
	cell.textLabel.text = 
	   [NSString stringWithFormat:@"第%d章", [indexPath row]];
    cell.accessoryType = 
		UITableViewCellAccessoryDisclosureIndicator;
	// Configure the cell.

    return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/


/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source.
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }   
}
*/


/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/


/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/


#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView 
	didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

	int chapter = [indexPath row] +1;
	
	BookViewController *bvc = [[BookViewController alloc]
				initWithNibName:@"BookViewController"
				bundle:nil];
	
	bvc->chapter = chapter;
	/*
	 bvc->chapter和 bvc.chapter是不一样的.
	 */
	bvc.page = 10;
	/* [bvc setPage:10]; */
	[self.navigationController 
		pushViewController:bvc
		animated:YES];
	[bvc release];
}


#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}


- (void)dealloc {
	self.settingBarButton = nil;
	self.settingBarButtonLeft = nil;
	self.segControl = nil;
    [super dealloc];
}


- (IBAction) rightClick:(id)sender
{
#if 0
	UIAlertView *av = [[UIAlertView alloc]
						initWithTitle:@"Right"
					   message:@"Right Message" 
					   delegate:self 
					   cancelButtonTitle:@"Cancel"
					   otherButtonTitles:@"OK", nil];
	[av show];
	[av release];
#endif
	SettingViewController *svc = [[SettingViewController alloc]
				initWithNibName:@"SettingViewController"
				bundle:nil];
	[self.navigationController 
			pushViewController:svc
			animated:YES];
	[svc release];
	/*
		1. 首先创建 SettingViewController 对象
		2. 然后把 SettingViewController对象通过
			pushViewController方法显示到前台
		3. 释放
	 */
}



@end

